<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="format-detection" content="telephone=no">
<meta http-equiv="Cache-Control" content="no-siteapp">
<link rel="stylesheet" href="../../../static/layui/css/layui.css" media="all" />
<link rel="stylesheet" href="../../../static/css/public.css" media="all" />
</head>
<body class="childrenBody">
	<form class="layui-form" id="search_form">
		<blockquote class="layui-elem-quote quoteBox">
			<form class="layui-form">
				<div class="layui-inline">
					<label class="layui-form-label">学生名</label>
					<div class="layui-input-inline">
						<input type="text" class="layui-input searchVal" id="name" name="name" placeholder="">
					</div>
				</div>
				<div class="layui-inline" has-permission="000500000020">
					<label class="layui-form-label">学校</label>
					<div class="layui-input-block">
						<select name="sid" id="sid" lay-search lay-filter="sid" class="searchVal">
							<option value="">请选择学校</option>
						</select>
					</div>
				</div>
				<!-- <div class="layui-inline" has-permission="000500000020">
					<label class="layui-form-label">专业</label>
					<div class="layui-input-block">
						<select name="did" id="did" lay-search class="searchVal" disabled>
							<option value="">请选择专业</option>
						</select>
					</div>
				</div> -->
				<div class="layui-inline" has-permission="000500000020">
					<label class="layui-form-label">学历</label>
					<div class="layui-input-block">
						<select name="ectn" id="ectn" lay-search class="searchVal">
							<!-- 学历：1-大专、2-本科、3-硕士研究生、4-高中、5-中专、6-小学、7-初中、8-中技、9-博士研究生、10-高技 -->
							<option value="">请选择</option>
							<option value="1">大专</option>
							<option value="2">本科</option>
							<option value="3">研究生</option>
							<option value="4">高中</option>
							<option value="5">中专</option>
							<option value="6">小学</option>
							<option value="7">初中</option>
							<option value="8">中技</option>
							<option value="9">博士</option>
							<option value="10">高技</option>
						</select>
					</div>
				</div>
				<div class="layui-inline" has-permission="000500000020">
					<label class="layui-form-label">上课方向</label>
					<div class="layui-input-block">
						<select name="ottn" id="ottn" lay-search class="searchVal">
							<option value="">请选择</option>
							<option value="1">前端</option>
							<option value="2">java后台</option>
						</select>
					</div>
				</div>
				<div class="layui-inline">
					<label class="layui-form-label">联系电话</label>
					<div class="layui-input-block">
						<input type="text" class="layui-input searchVal" name="phone" id="phone">
					</div>
				</div>
				<div class="layui-inline">
					<label class="layui-form-label">跟进人</label>
					<div class="layui-input-block">
						<select name="eid" id="eid" lay-search lay-filter="eid" class="searchVal">
							<option value="">请选择跟进人</option>
						</select>
					</div>
				</div>
				<div class="layui-inline" has-permission="000500000020">
					<label class="layui-form-label">招生模式</label>
					<div class="layui-input-block">
						<select name="elmt" id="elmt" lay-search class="searchVal">
							<option value="">请选择</option>
							<option value="1">社会招生</option>
							<option value="2">口碑转介绍招生</option>
							<option value="3">实训校招</option>
						</select>
					</div>
				</div>
				<div class="layui-inline" has-permission="000500000020">
					<label class="layui-form-label">意向</label>
					<div class="layui-input-block">
						<select name="intt" id="intt" lay-search class="searchVal">
							<option value="">请选择</option>
							<option value="1">有意向</option>
							<option value="2">没意向</option>
							<option value="3">潜在</option>
						</select>
					</div>
				</div>
				<div class="layui-inline" has-permission="001500200035">
					<label class="layui-form-label">开始时间</label>
					<div class="layui-input-block">
						<input type="text" class="layui-input searchVal" id="stime" name="stime" placeholder="">
					</div>
				</div>
				<div class="layui-inline" has-permission="001500200035">
					<label class="layui-form-label">结束时间</label>
					<div class="layui-input-block">
						<input type="text" class="layui-input searchVal" id="etime" name="etime" placeholder="">
					</div>
				</div>
				
				
			</form>
		</blockquote>
		<blockquote class="layui-elem-quote quoteBox">
			<div class="layui-inline">
				<a class="layui-btn search-btn" data-type="reload">搜索</a> 
				<a class="layui-btn layui-btn-normal insert-btn" has-permission="001500200000">添加</a> 
				<a class="layui-btn layui-btn-normal assignmentAll-btn" has-permission="001500200035">批量分配跟进人</a>
				<a class="layui-btn layui-btn-normal export-btn" has-permission="001500200040">导出数据</a>  
				<a class="layui-btn layui-btn-normal import_btn" has-permission="001500200045">导入数据</a> 
				<a class="layui-btn layui-btn-danger layui-btn-normal delAll-btn" has-permission="001500200010">批量删除</a>
			</div>
		</blockquote>
		<table id="list" lay-filter="list"></table>
		<div class="list-page" id="page"></div>
	</form>
	<script type="text/javascript" src="../../../static/js/jquery-2.1.1.min.js"></script>
	<script type="text/javascript" src="../../../static/layui/layui.js"></script>
	<script type="text/javascript" src="../../../static/custom/js/common.js"></script>
	<script type="text/javascript">
		layui.use([ 'form', 'layer', 'laydate','table', 'laypage', 'laytpl' , 'laydate'], function() {
			var laydate = layui.laydate;
			var listApi = '../../../advisory/customer/list';
			var toInsertHtml = 'insert.html';
			var toUpdateHtml = 'insert.html';
			var insertRecordsHtml = "insertRecords.html"
			var getRecordsHtml = "getRecords.html"
			
			var assignmentHtml = "assignment.html"
			
			var updateInterviewTimeHtml = "updateInterviewTime.html"
			
			var toImportHtml = 'import.html';
			
			var exportApi = "../../../advisory/customer/export"
			
			var deleteApi = '../../../advisory/customer/delete';
			var getEmployeeApi = "../../../getEmployee";
			var getDisciplineApi = "../../../getDiscipline";
			
			//初始化日期
			laydate.render({
				elem : '#stime'
			});
			//初始化日期
			laydate.render({
				elem : '#etime'
			});
			
			var cols = [ [ {
				fixed : "left",
				width : 50,
				title : '<input type="checkbox" lay-skin="primary"  id="check-all" class="check-all" lay-filter="check-all">',
				templet : function(d) {
					var str = '';
					if (!hasProtect(d)) {
						str += '<input type="checkbox" lay-skin="primary" class="check-one"  value="'+d.id+'" lay-filter="check-one">';
					} else {
						str += '<input type="checkbox" lay-skin="primary" class="check-one"  value="'+d.id+'" lay-filter="check-one" disabled >';
					}
					return str;
				}
			}, {
				field : 'sname',
				title : '学校',
				align : "center"
			}, {
				field : 'did',
				title : '专业',
				align : "center"
			}, {
				field : 'name',
				title : '学生名',
				align : "center"
			}, {
				field : 'phone',
				title : '电话',
				align : "center"
			},{
				field : 'email',
				title : '邮箱',
				align : "center"
			}, {
				field : 'ectn',
				title : '学历',
				align : "center",
				templet : function(d) {
					var ectn = d.ectn;
					//学历：1-大专、2-本科、3-硕士研究生、4-高中、5-中专、6-小学、7-初中、8-中技、9-博士研究生、10-高技
					if (ectn == 1) {
						return '大专';
					}
					if (ectn == 2) {
						return '本科';
					}
					if (ectn == 3) {
						return '研究';
					}
					if (ectn == 4) {
						return '高中';
					}
					if (ectn == 5) {
						return '中专';
					}
					if (ectn == 6) {
						return '小学';
					}
					if (ectn == 7) {
						return '初中';
					}
					if (ectn == 8) {
						return '中技';
					}
					if (ectn == 9) {
						return '博士';
					}
					if (ectn == 10) {
						return '高技';
					}
					if (!ectn) {
						return '';
					}
				}
			}, {
				field : 'wkyear',
				title : '工作经验',
				align : "center"
			}, /* {
				field : 'ottn',
				title : '上课方向',
				align : "center",
				templet : function(d) {
					var ottn = d.ottn;
					//上课方向：1-前端、2-java后台
					if (ottn == 1) {
						return '前端';
					}
					if (ottn == 2) {
						return 'java后台';
					}
					if (!ottn) {
						return '';
					}
				}
			}, {
				field : 'elmt',
				title : '招生模式',
				align : "center",
				templet : function(d) {
					var elmt = d.elmt;
					//招生模式：1-社会招生、2-口碑转介绍招生、3-实训校招
					if (elmt == 1) {
						return '社会招生';
					}
					if (elmt == 2) {
						return '口碑转介绍招生';
					}
					if (elmt == 3) {
						return '实训校招';
					}
					if (!elmt) {
						return '';
					}
				}
			}, */
			
			{
				field : 'ptap',
				title : '求职岗位',
				align : "center"
			},{
				field : 'rstype',
				title : '来源平台',
				align : "center",
				sort: true,
				templet : function(d) {
					var elmt = d.rstype;
					//简历类型：1-51job、2-智联、3-自定义
					if (elmt == 1) {
						return '51job';
					}
					if (elmt == 2) {
						return '智联';
					}
					if (elmt == 3) {
						return '其他';
					}
					if (!elmt) {
						return '';
					}
				}
			},{
				field : 'invite',
				title : '邀约公司',
				align : "center",
				sort: true,
				templet : function(d) {
					var elmt = d.invite;
					//邀约公司名字：1-数字桥信息网络科技有限公司、2-靖凯开源网络科技有限公司、3-合轩网络科技有限公司；
					if (elmt == 1) {
						return '数字桥信息网络科技有限公司';
					}
					if (elmt == 2) {
						return '靖凯开源网络科技有限公司';
					}
					if (elmt == 3) {
						return '合轩网络科技有限公司';
					}
					if (!elmt) {
						return '';
					}
				}
			},
			/* {
				field : 'intt',
				title : '意向',
				align : "center"
			},{
				field : 'ername',
				title : '跟进人',
				align : "center"
			},{
				field : 'mtime',
				title : '跟进时间',
				align : "center",
				templet : function(d) {
					var str ='';
					if(d.mtime){
						str+=d.mtime;
					}
					if(d.mcontent){
						str+=",";
						str+=d.mcontent;
					}
					return str;
				}
			},{
				field : 'etrname',
				title : '录入人',
				align : "center"
			},{
				field : 'ettm',
				title : '录入时间',
				align : "center"
			}, */
			{
				title : '操作',
				fixed : "right",
				align : "center",
				width : 390,
				templet : function(d) {
					var str = '';
					if (hasPermission('001500200035')) {
						str += '<a class="layui-btn layui-btn-xs" lay-event="assignment">分配跟进人</a>';
					}
					if (hasPermission('001500200020')) {
						str += '<a class="layui-btn layui-btn-xs" lay-event="getRecords">历史跟进</a>';
					}
					if (hasPermission('001500200025')) {
						str += '<a class="layui-btn layui-btn-xs" lay-event="insertRecords">添加跟进</a>';
					}
					if (hasPermission('001500200030')) {
						str += '<a class="layui-btn layui-btn-xs" lay-event="toUpdate">编辑</a>';
					}
					if (hasPermission('001500200050')) {
						str += '<a class="layui-btn layui-btn-xs" lay-event="toIvtm">预约面试</a>';
					}
					if (hasPermission('001500200005')) {
						str += '<a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="delete">删除</a>';
					}
					return str;
				}
			} ] ];
			var pram = merger(constant.page.toUri(), getsearchVal());
			var form = layui.form, layer = parent.layer === undefined ? layui.layer : top.layer;
			var $ = layui.jquery;
			var laytpl = layui.laytpl;
			var table = layui.table;
			var laypage = layui.laypage;
			var laydate = layui.laydate;
			tableIns = table.render({
				elem : '#list',
				cellMinWidth : constant.table.cellMinWidth,
				page : false,
				height : constant.table.height,
				cols : cols,
				done : function(res, page, count) {
					checkAll(form);
				}
			});
			//用户列表
			listLoad(pram);
			function listLoad(data) {
				loadAjax( listApi, "get", data, function(response) {
					baseCallBack(response, function(response) {
						table.reload("list", {
							data : response.data.records,
							limit : response.data.records.length
						})
						var page = laypage.render({
							elem : 'page',
							limits : constant.page.limits,
							limit : response.data.size,
							layout : constant.page.layout,
							curr : response.data.current,
							count : response.data.total,
							jump : function(obj, first) {
								if (!first) {
									pram = merger(constant.page.toUri(obj), getsearchVal());
									debugger;
									listLoad(pram);
								}
							}
						});
					});
				});
			}
			//初始化日期
			laydate.render({
				elem : '#period',//指定元素
				type: 'year' 
			});
			
			//搜索【此功能需要后台配合，所以暂时没有动态效果演示】
			$(".search-btn").on("click", function() {
				pram = merger(pram, getsearchVal());
				listLoad(pram);
			});

			//添加
			$(".insert-btn").click(function() {
				//openFullLayer("添加", toInsertHtml);
				openAreaLayer("添加", toInsertHtml, "600px", "480px");
			});

			
			//导出
			$(".export-btn").click(function() {
				confirmLayer('提示信息', '确定导出？', function(confirm, index) {
					function createObjectURL(object) { return (window.URL) ? window.URL.createObjectURL(object) : window.webkitURL.createObjectURL(object); }
					var xhr = new XMLHttpRequest();
					var formobj =  document.getElementById("search_form");    //用原生的js语法获取form表单dom
					// var formobj =  $("#modal_form").get(0);    //用 jquery获取form表单dom
					var formData = new FormData(formobj);
					xhr.open("POST", exportApi,true);
					xhr.setRequestHeader('jwttoken',cache.token.get());
					xhr.responseType = 'blob';
					xhr.onload = function (e) {
		            	if (this.status == 200) {
		                	var blob = this.response;
		                	var filename = "客户信息.xls";
		                	var a = document.createElement('a');
		                	blob.type = "application/excel";
		                	var url = createObjectURL(blob);
		                	a.href = url;
		                 	a.download = filename;
		                    a.click();
		                    window.URL.revokeObjectURL(url);
		                 }
		             };
					xhr.send(formData);
					confirm.close(index);
				})
			});
			//导入
			$(".import_btn").click(function() {
				openAreaLayer("添加", toImportHtml, "480px", "360px", true);
			});

			//批量删除
			$(".delAll-btn").click(function() {
				var ids = getCheckedId();
				if (ids && ids.length) {
					/* confirmLayer('提示信息', '确定删除？', function(confirm, index) {
						loadAjax( deleteApi + "/" + ids, "delete", null, function(response) {
							baseCallBack(response, function(response) {
								layer.msg(response.msg);
								listLoad(pram);
								confirm.close(index);
							});
						});
					}) */
					layer.open({
						  icon:3,
						  title:'提示信息',
						  content: '确定删除？删除原因：<input type="text" class="layui-input searchVal" placeholder="">'
						  ,btn: ['确定', '取消']
						  ,yes: function(index, layero){
							  var reason = layero.children(".layui-layer-content").children(".layui-input").val();
							  loadAjax( deleteApi + "/" + ids+"?reason="+reason, "delete", null, function(response) {
									baseCallBack(response, function(response) {
										layer.msg(response.msg);
										listLoad(pram);
										confirm.close(index);
									});
								});
						  }
						});
					

				} else {
					layer.msg("请选择需要删除的数据");
				}
			});

			
			//批量分配跟进人
			$(".assignmentAll-btn").click(function() {
				//多选获取用户id
				var ids = getCheckedId();
				if (ids && ids.length) {
					//openFullLayer("批量分配跟进人", assignmentHtml + "/" + ids);
					//openAreaLayer("批量分配跟进人", assignmentHtml + "?id=" + ids, "480px", "360px", true);
					openAreaLayer("批量分配跟进人", assignmentHtml + "?id=" + ids, "680px", "460px", true);
				} else {
					layer.msg("请选择需要分配跟进人的数据");
				} 
			});
			
			//列表操作
			table.on('tool(list)', function(obj) {
				var layEvent = obj.event;
				var data = obj.data;
				if (layEvent === 'assignment') {
					//分配跟进人
					openAreaLayer("分配跟进人", assignmentHtml + "?id=" + data.id, "600px", "400px");
				}else if (layEvent === 'getRecords') {
					//历史跟进
					openFullLayer("历史跟进", getRecordsHtml + "?id=" + data.id);
				} else if (layEvent === 'insertRecords') {
					//添加跟进
					openAreaLayer("添加跟进", insertRecordsHtml + "?id=" + data.id, "800px", "600px");
				} else if (layEvent === 'toUpdate') {
					//编辑
					openAreaLayer("编辑", toUpdateHtml + "?id=" + data.id, "600px", "500px");
				} else if (layEvent === 'delete') {
					//删除
					/* confirmLayer('提示信息', '确定删除？', function(confirm, index) {
						loadAjax( deleteApi + "/" + data.id, "delete", null, function(response) {
							baseCallBack(response, function(response) {
								layer.msg(response.msg);
								listLoad(pram);
								confirm.close(index);
							});
						});
					}) */
					layer.open({
						  icon:3,
						  title:'提示信息',
						  content: '确定删除？删除原因：<input type="text" class="layui-input searchVal" placeholder="">'
						  ,btn: ['确定', '取消']
						  ,yes: function(index, layero){
							  var reason = layero.children(".layui-layer-content").children(".layui-input").val();
							  loadAjax( deleteApi + "/" + data.id+"?reason="+reason, "delete", null, function(response) {
									baseCallBack(response, function(response) {
										layer.msg(response.msg);
										listLoad(pram);
										confirm.close(index);
									});
								});
						  }
						});
					
					
				}else if (layEvent === 'toIvtm') {
					//添加跟进
					openAreaLayer("预约面试", updateInterviewTimeHtml + "?id=" + data.id, "600px", "400px");
				}
			})
			
			//监听表格排序问题//字段排序
			  table.on('sort(list)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
				  /* console.log(obj.field); //当前排序的字段名
				  console.log(obj.type); //当前排序类型：desc（降序）、asc（升序）、null（空对象，默认排序）
				  console.log(this); //当前排序的 th 对象
				  console.log(pram); */
				  pram['orderField']=obj.field;
				  pram['orderDirection']=obj.type;
				  listLoad(pram);
				});
			
			
			
			
			//查找学校
			loadAjax( "../../../getSchool", "get", null, function(response) {
				baseCallBack(response, function(response) {
					$("#sid").empty();
					var str = '<option value="">请选择</option>';
					for( data of response.data){
						str+='<option value="'+data.id+'">'+data.name+'</option>';
					}
					$("#sid").append(str);
					form.render('select');
				});
			});
			//查找跟进人
			loadAjax( getEmployeeApi, "get", null, function(response) {
				baseCallBack(response, function(response) {
					$("#eid").empty();
					var str = '<option value="">请选择</option>';
					for( data of response.data){
						str+='<option value="'+data.id+'">'+data.rname+'</option>';
					}
					$("#eid").append(str);
					form.render();

				});
			});
			//获取所有专业信息
			function getDiscipline(id){
				loadAjax( getDisciplineApi+"/"+id, "get", null, function(response) {
					var str='';
					$("#did").empty();
					str += '<option value="">请选择专业</option>';
					$("#did").attr("disabled",true);
					baseCallBack(response, function(response) {
					    if (response.data && response.data.length) {
						    $("#did").attr("disabled",false);
						    for( data of response.data){
						  	    str+='<option value="'+data.id+'">'+data.name+'</option>';
						    }
					    }
						$("#did").append(str);
					});
					form.render('select');
				});
			}
			form.on('select(sid)', function(data){
				  var id= data.value?data.value:'0';
				  //获取所有专业信息
				  //getDiscipline(id);
				  form.render();
			}); 
		})
	</script>
</body>
</html>